package com.lanchewuyou.user.driver.yancheui;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.Toast;

import com.lanchewuyou.user.driver.R;
import com.lanchewuyou.user.driver.layouts.YancheFinishDialog;
import com.lanchewuyou.user.driver.modul.Config;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * 验车结束页面
 */
public class YancheOverActivity extends AppCompatActivity implements View.OnClickListener {
    private static String DRIVERID;
    private ImageButton yancheOverBack;
    private Button yancheOverNext;
    private ArrayAdapter adapter;
    private List<String> list;
    private Spinner yancheOverSpinner;
    private RelativeLayout yancheOverRela;
    private YancheFinishDialog.Builder builder;
    private String yuyueTime = "暂无";
    private Toast toast;

    private void showTextToast(String msg) {
        if (toast == null) {
            toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
        } else {
            toast.setText(msg);
        }
        toast.show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yanche_over);
        SharedPreferences sharedPreferences = getSharedPreferences(Config.PASSWORD_PATH, Activity.MODE_PRIVATE);
        DRIVERID = sharedPreferences.getString("driverid", "");
        initViews();

    }

    private void initViews() {
        yancheOverBack = (ImageButton) findViewById(R.id.yanche_over_back);
        yancheOverBack.setOnClickListener(this);
        yancheOverNext = (Button) findViewById(R.id.yanche_over_next_btn);
        yancheOverNext.setOnClickListener(this);
        yancheOverSpinner = (Spinner) findViewById(R.id.yanche_over_spinner);
        yancheOverRela = (RelativeLayout) findViewById(R.id.yanche_over_rela);
        yancheOverRela.setOnClickListener(this);
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
        list = new ArrayList<>();
        list.add("暂定");
        for (int i = 0; i < 10; i++) {
            Calendar cal = Calendar.getInstance();// 取当前日期。
            cal.add(Calendar.DAY_OF_MONTH, +i);
            String data = format.format(cal.getTime());
            list.add(data);
        }
        adapter = new ArrayAdapter<String>(this, R.layout.yanche_spinner_item, list);
        //第三步：为适配器设置下拉列表下拉时的菜单样式。
        adapter.setDropDownViewResource(R.layout.yanche_spinner_item);
        yancheOverSpinner.setAdapter(adapter);
        yancheOverSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                parent.setVisibility(View.VISIBLE);
                yuyueTime = list.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                parent.setVisibility(View.VISIBLE);
            }
        });
        builder = new YancheFinishDialog.Builder(this).setMessage("您已成功提交行驶路线").setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.yanche_over_back:

                break;
            case R.id.yanche_over_next_btn:
                builder.create().show();
                break;
            case R.id.yanche_over_rela:

                break;
            default:
                break;
        }
    }
}
